<?php 
// Manager sessions
class __SESSION
{
	private static $_instance;
	private $_sessionPath;
	private $_sessionName = array();

	public function __construct()
	{}

	public static function getInstance()
	{
		if (!self::$_instance) self::$_instance = new self();

		return self::$_instance;
	}

	public function start()
	{
		if (headers_sent())
		{
			//__ERROR::getInstance()->throw('Header Already Sended!');
			die('Header already sended!');
		}
		$this->_sessionSetup();
		session_start();
	}

	private function _sessionSetup()
	{
		$this->_sessionPath = @session_save_path();
	}

	public function addSession($sessionName, $sessionValue = '', $cryptSession = false)
	{
		if ($cryptSession) $sessionValue = $this->cryptSession($sessionValue);
		$this->_sessionName[] = $sessionName;
		return $_SESSION["$sessionName"] = $sessionValue;
		return false;
	}

	public function deleteSession($sessionName)
	{
		if(isset($_SESSION["$sessionName"])) $_SESSION["$sessionName"] = null;
		session_unset("$sessionName");
	}

	public function clearAllSession()
	{
		@session_destroy();
	}
	
	public function cryptSession($sessionValue)
	{
		return $sessionValue;
	}
	
	public function getSession($session_name)
	{
		if (!$_SESSION["$session_name"]) return FALSE;
		
		return $_SESSION[$session_name];
	}
}